package com.quanshu.change.person.view;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.gyf.barlibrary.ImmersionBar;
import com.quanshu.change.person.adapter.GoldListAdapter;
import com.quanshu.change.person.entity.GoldListEntity;
import com.quanshu.exchange.R;
import com.quanshu.exchange.support.api.ShopInterface;
import com.quanshu.exchange.support.net.BaseResponse;
import com.quanshu.exchange.support.net.core.BaseObserver;
import com.quanshu.exchange.support.net.core.BaseTransformer;
import com.quanshu.exchange.support.net.core.NetClient;
import com.quanshu.exchange.support.utils.LogUtil;
import com.quanshu.exchange.ui.base.BaseActivity;
import com.quanshu.shop.base.view.BaseTitleBar;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GoldListActivity extends BaseActivity {

    @BindView(R.id.rl)
    RecyclerView rl;
    @BindView(R.id.title_bar)
    BaseTitleBar titleBar;
    private GoldListAdapter goldListAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gold_list);
        ButterKnife.bind(this);
        initView();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy();
    }

    private void initView() {
        ImmersionBar.with(this).statusBarColor("#FFFFFF").titleBar(titleBar).statusBarDarkFont(true).init();

        titleBar.setLeftImage(R.drawable.icon_back_black_2_0).setCenterText("收支明细").setOnClickBaseTitleListener(new BaseTitleBar.OnClickBaseTitleBarListener() {
            @Override
            public void onclickLeft() {
                finish();
            }

            @Override
            public void onclickRight() {

            }
        });
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        rl.setLayoutManager(linearLayoutManager);
        getData();
    }

    //获取金豆列表
    private void getData() {
        if (currentUser != null) {
            NetClient.getInstance().getShopService(ShopInterface.class)
                    .getGoldList(currentUser.getId())
                    .compose(new BaseTransformer<>(this, true, false))
                    .subscribe(new BaseObserver<BaseResponse<List<GoldListEntity>>>() {
                        @Override
                        public void onSuccess(BaseResponse<List<GoldListEntity>> response) {
                            if (response.getCode() == 1) {
                                goldListAdapter = new GoldListAdapter(response.getData());
                                rl.setAdapter(goldListAdapter);
                            }
                        }

                        @Override
                        public void onFailure(Throwable e) {
                            LogUtil.printException(e);
                        }
                    });
        }
    }
}
